package com.dom.domweb.modular.controller;

import com.dom.common.model.vo.stor.*;
import com.dom.domweb.common.RspModel;
import com.dom.domweb.common.TabPager;
import com.dom.domweb.modular.service.StorOrderService;
import com.dom.domweb.utils.TradeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description 入库单控制层
 * @Author xllei
 * @Date 2018/12/21 2:30 PM
 * @Version 1.0
 **/
@RestController
@RequestMapping(value = "/stor/stockout")
public class StorStockoutController {
    @Autowired
    private StorOrderService storOrderService;

    @RequestMapping(value="/getStockoutPager", method = RequestMethod.GET)
    public TabPager getStockinPager(@RequestParam("limit")int limit, @RequestParam("page")int page,
                                    @RequestParam("storCode")Integer storCode, @RequestParam("stockDate")String stockDate,
                                    @RequestParam("stockType")Integer stockType, @RequestParam("organCode") Integer organCode,
                                    @RequestParam("stat") Integer stat, @RequestParam("verfyStat") Integer verfyStat){
        S039R request = new S039R();
        TradeUtil.setHead(request);

        request.setPn(page);
        request.setPs(limit);
        request.setStorCode(storCode);
        request.setStockDate(stockDate);
        request.setStockType(stockType);
        request.setOrganCode(organCode);
        request.setStat(stat);
        request.setVerfyStat(verfyStat);

        S039A response = storOrderService.findStockoutPager(request);

        return new TabPager(response.getStockoutInfos(), response.getTotalNum());
    }

    @RequestMapping(value = "/addStockout", method = RequestMethod.POST)
    public RspModel addStockout(@RequestBody S030R request){
        //赋值交易报文头
        TradeUtil.setHead(request);

        S030A response = storOrderService.addStockoutBill(request);

        return new RspModel(response.getStockId());
    }

    @RequestMapping(value = "/getStockoutDetailList", method = RequestMethod.GET)
    public TabPager getStockoutDetailList(@RequestParam("stockId") Integer stockId){
        S049R request = new S049R();
        // 赋值交易报文头
        TradeUtil.setHead(request);
        request.setStockId(stockId);
        request.setPagination(false);

        // 调用查询入库单明细
        S049A response = storOrderService.findStockoutDetail(request);
        return new TabPager(response.getStockDetailData(), response.getTotalNum());
    }

    @RequestMapping(value = "/editStockout", method = RequestMethod.POST)
    public RspModel editStockout(@RequestBody S032R request) {
        TradeUtil.setHead(request);

        S032A response = storOrderService.editStockoutBill(request);
        return new RspModel(response.getStockId());
    }

    @RequestMapping(value = "/delStockout", method = RequestMethod.POST)
    public RspModel delStockout(@RequestParam("stockId") Integer stockId){
        S031R request = new S031R();
        TradeUtil.setHead(request);

        request.setStockId(stockId);
        S031A response = storOrderService.delStockoutBill(request);
        return new RspModel(response.getStockId());
    }
}
